{% extends 'marketing/base.html' %}
{% load static %}
{% load paginate %}
{% block content %}
{{ block.super }}
<nav aria-label="breadcrumb">
  <ol class="breadcrumb mb-3">
    <li class="breadcrumb-item"><a href="{% url 'marketing:contacts_list' %}">Contacts</a></li>
    <li class="breadcrumb-item active">Edit</li>
  </ol>
</nav>
<div class="main_container ml-5 mr-5">
  <div class="row marl">
    <div class="col-md-12">
      <form id="add_form" method="POST" action='' novalidate>
        <div class="overview_form_block row marl justify-content-center">
          <div class="col-md-5">
            <div class="card">
              <div class="card-body">
                <div class="card-title text-center">
                  Edit Contact
                </div>
                <div class="row marl no-gutters justify-content-center">
                  <div class="col-md-12">
                    <div class="filter_col col-md-12">
                      <div class="form-group">
                        <label for="exampleInputEmail1" class="required">
                          Email{% if form.email.field.required %}<span class="error_marker"
                            style="color:red">*</span>{% endif %}</label>
                        {{ form.email }}
                        <span class="error" id="id__email">{{ form.email.errors }}</span>
                      </div>
                    </div>
                    <div class="filter_col col-md-12">
                      <div class="form-group">
                        <label for="exampleInputEmail1" class="required">
                          Company{% if form.company_name.field.required %}<span class="error_marker"
                            style="color:red">*</span>{% endif %}</label>
                        {{ form.company_name }}
                        <span class="error" id="id__company_name">{{ form.company_name.errors }}</span>
                      </div>
                    </div>
                    <div class="filter_col col-md-12">
                      <div class="form-group">
                        <label for="exampleInputEmail1" class="required">First
                          Name{% if form.name.field.required %}<span class="error_marker"
                            style="color:red">*</span>{% endif %}</label>
                        {{ form.name }}
                        <span class="error" id="id__name">{{ form.name.errors }}</span>
                      </div>
                    </div>
                    <div class="filter_col col-md-12">
                      <div class="form-group">
                        <label for="exampleInputEmail1" class="required">Last
                          Name{% if form.last_name.field.required %}<span class="error_marker"
                            style="color:red">*</span>{% endif %}</label>
                        {{ form.last_name }}
                        <span class="error" id="id__last_name">{{ form.last_name.errors }}</span>
                      </div>
                    </div>
                    <div class="filter_col col-md-12">
                      <div class="form-group">
                        <label for="exampleInputEmail1" class="required">City
                          {% if form.city.field.required %}<span class="error_marker"
                            style="color:red">*</span>{% endif %}</label>
                        {{ form.city }}
                        <span class="error" id="id__city">{{ form.city.errors }}</span>
                      </div>
                    </div>
                    <div class="filter_col col-md-12">
                      <div class="form-group">
                        <label for="exampleInputEmail1" class="required">State
                          {% if form.state.field.required %}<span class="error_marker"
                            style="color:red">*</span>{% endif %}</label>
                        {{ form.state }}
                        <span class="error" id="id__state">{{ form.state.errors }}</span>
                        <input type="hidden" name="from_url" value="{{request.GET.from_contact}}">
                      </div>
                    </div>
                  </div>
                  <div class="col-md-12">
                    <div class="row marl buttons_row text-center form_btn_row">
                      <button class="btn btn-default save" type="submit">Update</button>
                      <a {% if request.META.HTTP_REFERER %} href="{{ request.META.HTTP_REFERER }}" {% else %} href="/"
                        {% endif %} class="btn btn-default clear">Cancel</a>
                      
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </form>
    </div>
  </div>
</div>
{% endblock %}
{% block js_block %}
<script type="text/javascript">

  // $(document).ready(function() {
  //   $('.assigned_users').select2();
  // });
  $(document).ready(function () {

  });

  $('form#add_form').ajaxForm({
    type: 'POST',
    dataType: 'json',
    url: ".",
    data: $('#add_form').serialize(),
    success: function (data) {
      if (data.error) {
        $('.error').html('')
        for (var key in data.errors) {
          $('#id__' + key).html("<p>" + data.errors[key][0] + "</p>");
        };
        $('#submit_btn').removeAttr('disabled')
      }
      else {
        window.location = data.success_url;
      }
    }
  });
</script>
{% endblock js_block %}